package cn.net.chenbao.medical.base;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import cn.net.chenbao.medical.dialog.LoadingDialog;

public class BaseActivity extends AppCompatActivity implements IBaseView {
    private LoadingDialog mLoadingDialog;

    protected void showLoading() {
        try {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    if (mLoadingDialog == null) {
                        mLoadingDialog = new LoadingDialog(BaseActivity.this);
                    }
                    if (mLoadingDialog.isShowing()) {
                        return;
                    }
                    mLoadingDialog.show();
                }
            });
        } catch (Exception e) {

        }
    }

    protected void dimissDialog() {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                if (mLoadingDialog != null && mLoadingDialog.isShowing()) {
                    mLoadingDialog.dismiss();
                }
            }
        });
    }

    @Override
    public void loadStart(boolean isShow) {
        if (isShow) {
            showLoading();
        }
    }

    @Override
    public void loadFinish() {
        dimissDialog();
    }
}
